package cn.com.assistant.utils;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.http.HttpStatus;

import java.io.Serializable;

@ApiModel(
    description = "请求响应数据"
)
public class ResponseMessage<T> implements Serializable {
    private static final long serialVersionUID = 7514826298158585250L;
    public static final int SUCCESS = 1;
    public static final int FAILED = 0;
    public static final int ERROR_CODE_CIRCUIT_BREAKER = 10400;
    public static final String MSG_SUCCESS = "success";
    public static final String MSG_FAIL = "fail";
    @ApiModelProperty("状态码 1：成功，0：失败")
    private Integer status;
    @ApiModelProperty("消息默认success表示成功")
    private Object msg;
    @ApiModelProperty("数据对象")
    private T data;
    @ApiModelProperty("错误码,默认值为0")
    private Integer errorCode = 0;

    public static final ResponseMessage defaultResponse() {
        ResponseMessage rm = new ResponseMessage();
        return rm.setStatus(1).setMsg("success");
    }

    public static final ResponseMessage validFailResponse() {
        ResponseMessage rm = new ResponseMessage();
        return rm.setStatus(0).setMsg("输入校验失败");
    }

    public static final Boolean success(ResponseMessage responseMessage) {
        return 1 == responseMessage.getStatus();
    }

    public static ResponseMessage defaultFallBack() {
        ResponseMessage rm = new ResponseMessage();
        return rm.setStatus(1).setErrorCode(10400).setMsg("当前系统繁忙，请稍后再试...");
    }

    public static ResponseMessage failResponse() {
        ResponseMessage rm = new ResponseMessage();
        return rm.setStatus(0).setErrorCode(HttpStatus.INTERNAL_SERVER_ERROR.value()).setMsg("");
    }

    public Integer getStatus() {
        return this.status;
    }

    public Object getMsg() {
        return this.msg;
    }

    public T getData() {
        return this.data;
    }

    public Integer getErrorCode() {
        return this.errorCode;
    }

    public ResponseMessage<T> setStatus(final Integer status) {
        this.status = status;
        return this;
    }

    public ResponseMessage<T> setMsg(final Object msg) {
        this.msg = msg;
        return this;
    }

    public ResponseMessage<T> setData(final T data) {
        this.data = data;
        return this;
    }

    public ResponseMessage<T> setErrorCode(final Integer errorCode) {
        this.errorCode = errorCode;
        return this;
    }

    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof ResponseMessage)) {
            return false;
        } else {
            ResponseMessage<?> other = (ResponseMessage)o;
            if (!other.canEqual(this)) {
                return false;
            } else {
                label59: {
                    Object this$status = this.getStatus();
                    Object other$status = other.getStatus();
                    if (this$status == null) {
                        if (other$status == null) {
                            break label59;
                        }
                    } else if (this$status.equals(other$status)) {
                        break label59;
                    }

                    return false;
                }

                Object this$msg = this.getMsg();
                Object other$msg = other.getMsg();
                if (this$msg == null) {
                    if (other$msg != null) {
                        return false;
                    }
                } else if (!this$msg.equals(other$msg)) {
                    return false;
                }

                Object this$data = this.getData();
                Object other$data = other.getData();
                if (this$data == null) {
                    if (other$data != null) {
                        return false;
                    }
                } else if (!this$data.equals(other$data)) {
                    return false;
                }

                Object this$errorCode = this.getErrorCode();
                Object other$errorCode = other.getErrorCode();
                if (this$errorCode == null) {
                    if (other$errorCode != null) {
                        return false;
                    }
                } else if (!this$errorCode.equals(other$errorCode)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof ResponseMessage;
    }

    public String toString() {
        return "ResponseMessage(status=" + this.getStatus() + ", msg=" + this.getMsg() + ", data=" + this.getData() + ", errorCode=" + this.getErrorCode() + ")";
    }

    public ResponseMessage() {
    }
}